package com.lixiaoyi.emp.controller;

import com.lixiaoyi.emp.entity.Emp;
import com.lixiaoyi.emp.entity.Page;
import com.lixiaoyi.emp.service.IEmpManagerService;
import com.lixiaoyi.emp.service.IEmpService;
import com.lixiaoyi.emp.service.impl.EmpManagerServiceImpl;
import com.lixiaoyi.emp.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author 李小毅
 * @Description
 * @Date 2022-05-12
 */
//@WebServlet(name = "showAllEmpController",value = "/showAllEmpController")

@WebServlet("/manager/safe/showAllEmpController")
public class showAllEmpController extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String pageNum = request.getParameter("pageNum");
        //如果第一次登陆
        if (pageNum == null){
            pageNum = "1";
        }
        Page page = new Page(Integer.valueOf(pageNum));

        IEmpService empService = new EmpServiceImpl();

        List<Emp> emps =  empService.showAllEmp(page);

        request.setAttribute("emps",emps);

        request.setAttribute("page",page);

        request.getRequestDispatcher("/manager/safe/showAllEmp.jsp").forward(request,response);
        //request.getRequestDispatcher("/manager/safe/showAllEmpJSP").forward(request,response);




    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doPost(request,response);
    }
}
